package com.itheima.task;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
* 2. 分析以下需求，并用代码实现：
	(1)统计每个单词出现的次数
	(2)有如下字符串"If you want to change your fate I think you must come to the dark horse to learn java"(用空格间隔)
	(3)打印格式：
		to=3
  		think=1
  		you=2
  		//........
* */
public class PircticeStream02 {
    public static void main(String[] args) {
        String test ="If you want to change your fate I think you must come to the dark horse to learn java";
        Map<String, Integer> map = new HashMap<>();
        String[] arr = test.split(" ");
        for (String  word:arr) {
            map.put(word,map.containsKey(word)?map.get(word)+1:1);
        }
        Set<String> keys = map.keySet();
        for (String key:keys) {
            System.out.println(key+"="+map.get(key));
        }
    }
}
